#include <a_samp>
#include <sscanf2>
#include <YSF>

#define dcmd(%1,%2,%3)      			if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define COLOR_GREEN          			0x33AA33AA
#define COLOR_RED            			0xFF0000FF
#define COLOR_YELLOW         			0xFFFF00AA
#define COLOR_BLUE           			0x00FFFFFF
#define COLOR_AMSG         				0xFF00FFFF
#define COLOR_GREY             			0xAFAFAFAA

#define COLOR_MISSIONTEXT				0xFFFFFFFF

#define MISSIONS_VERSION				"0.1 alpha"
#define MISSIONS_FOLDER					"missions/" 	//Must end with a "/" or "\\" if it is a new folder, to get missions from scriptfiles, leave blank: ""
#define MISSIONS_FILE_PATTERN			"*.mis" 		//Files that match this pattern will be parsed as missions


//It's best to keep these numbers as close as to the real number as possible
#undef MAX_PLAYERS
#define MAX_PLAYERS						32				//IMPORTANT! Set this number to your server's slot number

#define MAX_MISSIONS					10				//Maximum number of missions
#define MAX_MISSION_STEPS				20				//Maximum number of steps a mission can have
#define MAX_MISSION_SUBSTEPS			30				//Maximum number of substeps a step can have
#define MAX_STEP_TEXTS					5				//Maximum number of MissionTexts a step can display

#define MAX_VARIABLES					20				//Maximum number of variables that can be declared in a misson script
#define MAX_VARIABLE_NAME				30				//Maximum length of a variable

#define MAX_SCRIPT_VEHICLES				20				//Maximum number of total vehicles that can be created by all of the missions together
#define MAX_SCRIPT_MONEY				50				//Maximum number of total amount the script can store GiveMissionMoney

#define VARIABLE_TYPE_INT				1
#define VARIABLE_TYPE_STRING			2

#define STEP_MISSIONTEXT				1
#define STEP_MISSIONCAR					2
#define STEP_END						3
#define STEP_CREATEVEHICLE				4
#define STEP_SETTARGET					5
#define STEP_GIVEMONEY					6

#define MISSION_COMMAND					1
#define MISSION_LOCATION				2
#define MISSION_AUTO					3
#define MISSION_VEHICLE					4

#define DEBUG											//Enable debugging?

#define DISPLAY_PARSING_TIME			true 			//If you experience problems with tickcount(), set this to false

new stock FALSE = false;
#define SendMsg(%1,%2,%3,%4) 			do{new sendfstring[128];format(sendfstring,256,(%3),%4);SendClientMessage((%1),(%2),sendfstring);}while(FALSE)
#define SendAllMsg(%1,%2,%3) 			do{new sendfstring[128];format(sendfstring,256,(%2),%3);SendClientMessageToAll((%1),sendfstring);}while(FALSE)
#define IsPlayerSpawned(%1)				IsPSpawned[(%1)]

forward Rem_TriggerMission(playerid, missionname[]);
forward Rem_TriggerNextStep(playerid, missionname[]);

enum eMissionPlot
{
	eStepType[MAX_MISSION_SUBSTEPS],
	eArrayNum[MAX_MISSION_SUBSTEPS]
}
new MissionPlot[MAX_MISSIONS][MAX_MISSION_STEPS][eMissionPlot];

new MissionName[MAX_MISSIONS][128];

new DisplayText[MAX_MISSIONS*MAX_STEP_TEXTS*MAX_MISSION_SUBSTEPS][128];

new MissionTrigger[MAX_MISSIONS];
new MissionTrigger_Command[MAX_MISSIONS][128];
enum eMissionTrigger_Location
{
	Float:eMissionX,
	Float:eMissionY,
	Float:eMissionZ,
	Float:eMissionR
}
new MissionTrigger_Location[MAX_MISSIONS][eMissionTrigger_Location];

new MissionMove[MAX_MISSIONS][MAX_MISSION_STEPS];
enum eMissionMove_Location
{
	Float:eMMoveX,
	Float:eMMoveY,
	Float:eMMoveZ,
	Float:eMMoveR
}
new MissionMove_Location[MAX_MISSIONS][MAX_MISSION_STEPS][eMissionMove_Location];

enum eVariables
{
	eVarType,
	eVarName[MAX_VARIABLE_NAME]
}
new Variables[MAX_MISSIONS][MAX_VARIABLES][eVariables];
new Variables_ValuesInt[MAX_MISSIONS][MAX_PLAYERS][MAX_VARIABLES];
new Variables_ValuesString[MAX_MISSIONS][MAX_PLAYERS][MAX_VARIABLES];
new Variables_String[MAX_MISSIONS*MAX_PLAYERS*MAX_VARIABLES][128];

enum eMission_VehicleStorage
{
	eVS_modelid,
	Float:eVS_X,
	Float:eVS_Y,
	Float:eVS_Z,
	Float:eVS_R,
	eVS_respawn,
	eVS_c1,
	eVS_c2,
	eVS_Var[MAX_VARIABLE_NAME]
}
new Mission_VehicleStorage[MAX_SCRIPT_VEHICLES][eMission_VehicleStorage];

enum eMission_TargetCar
{
	eTC_Var[MAX_VARIABLE_NAME],
	eTC_Toggle
}
new Mission_TargetCar[MAX_MISSIONS*MAX_MISSION_STEPS*MAX_MISSION_SUBSTEPS][eMission_TargetCar];

new Mission_Money[MAX_SCRIPT_MONEY];

new Player_Step[MAX_PLAYERS][MAX_MISSIONS];

new IsPSpawned[MAX_PLAYERS];

new WasInArea[MAX_PLAYERS][MAX_MISSIONS];

new Veh_Target[MAX_PLAYERS][MAX_VEHICLES];

stock LoadMissions()
{
	new 
		buf[128],
		i,
		readLine,
		read[256],
		File:mFile,
		string[128],
		string2[128],
		int,
		int2,
		int3,
		int4,
		mStep = -1,
		mTextArray,
		mStepNum,
		Float:X,
		Float:Y,
		Float:Z,
		Float:R,
		End = 0,
		mVehArray,
		varstring[128],
		mTargetArray,
		inComment,
		mMoneyArray,
		tick = tickcount();
	while(ffind(#MISSIONS_FOLDER #MISSIONS_FILE_PATTERN, buf, sizeof(buf), i))
	{
		format(buf, 128, "%s%s", MISSIONS_FOLDER, buf);
		#if defined DEBUG
		printf("%s(1) DEBUG: Started parsing %s", buf, buf);
		#endif
		mFile = fopen(buf, io_read);
		readLine = 0;
		mStep = -1;
		End = 0;
		inComment = 0;
		while(fread(mFile, read))
		{
			StripNewLine(read);
			readLine++;
			if(strfind(read, "/*") != -1) inComment++;
			if(strfind(read, "*/") != -1)
			{			
				inComment--; 
				continue;
			}
			if((read[0] == '/' && read[1] == '/') || inComment) continue;
			if(!sscanf(read, "p<|>'SetMissionName's[128]", string))
			{
				if(readLine == 1)
				{
					#if defined DEBUG
					printf("%s(%i) DEBUG: SetMissionName(%s)", buf, readLine, string);
					#endif
					format(MissionName[i], 128, string);
				}
				else 
				{
					printf("%s(%i) ERROR: First line must be SetMissionName", buf, readLine);
					break;
				}
			}
			else if(readLine == 1 && sscanf(read, "p<|>'SetMissionName's[128]", string))
			{
				printf("%s(%i) ERROR: First line must be SetMissionName", buf, readLine);
				break;
			}
			else if(!sscanf(read, "p<|>'SendMissionText's[128]", string))
			{
				#if defined DEBUG
				printf("%s(%i) DEBUG: SendMissionText(%s)", buf, readLine, string);
				#endif
				MissionPlot[i][mStep][eStepType][mStepNum] = STEP_MISSIONTEXT;
				MissionPlot[i][mStep][eArrayNum][mStepNum] = mTextArray;
				format(DisplayText[mTextArray], 128, string);
				mStepNum++;
				mTextArray++;
			}
			else if(!sscanf(read, "p<|>'SetMissionTrigger's[128]s[128]", string, string2))
			{
				if(!strcmp(string, "command", true))
				{
					#if defined DEBUG
					printf("%s(%i) DEBUG: SetMissionTrigger(%s, %s)", buf, readLine, string, string2);
					#endif
					if(string2[0] != '/')
					{
						printf("%s(%i) ERROR: Command must start with a '/'", buf, readLine);
						break
					}
					MissionTrigger[i] = MISSION_COMMAND;
					format(MissionTrigger_Command[i], 128, string2);
				}
				else if(!strcmp(string, "location", true))
				{
					if(sscanf(string2, "p<|>ffff", X, Y, Z, R)) 
					{
						printf("%s(%i) ERROR: Location must be 'X|Y|Z|R'", buf, readLine);
						break;
					}
					#if defined DEBUG
					printf("%s(%i) DEBUG: SetMissionTrigger(%s, %f, %f, %f, %f)", buf, readLine, string, X, Y, Z, R);
					#endif
					MissionTrigger[i] = MISSION_LOCATION;
					MissionTrigger_Location[i][eMissionX] = X;
					MissionTrigger_Location[i][eMissionY] = Y;
					MissionTrigger_Location[i][eMissionZ] = Z;
					MissionTrigger_Location[i][eMissionR] = R;
				}
			}
			else if(!sscanf(read, "p<=>s[" #MAX_VARIABLE_NAME "]s[128]", varstring, string2))
			{
				if(!sscanf(string2, "p<|>'CreateVehicle'iffffiii", int, X, Y, Z, R, int3, int4, int2))
				{
					#if defined DEBUG
					printf("%s(%i) DEBUG: CreateVehicle(%i, %f, %f, %f, %f, %i, %i, %i)", buf, readLine, int, X, Y, Z, R, int3, int4, int2);
					#endif
					if(mStep == -1) SetVarValueInt(i, varstring, CreateVehicle(int, X, Y, Z, R, int3, int4, int2));
					else
					{
						Mission_VehicleStorage[mVehArray][eVS_modelid] = int;
						Mission_VehicleStorage[mVehArray][eVS_X] = X;
						Mission_VehicleStorage[mVehArray][eVS_Y] = Y;
						Mission_VehicleStorage[mVehArray][eVS_Z] = Z;
						Mission_VehicleStorage[mVehArray][eVS_R] = R;
						Mission_VehicleStorage[mVehArray][eVS_respawn] = int2;
						Mission_VehicleStorage[mVehArray][eVS_c1] = int4;
						Mission_VehicleStorage[mVehArray][eVS_c2] = int3;
						format(Mission_VehicleStorage[mVehArray][eVS_Var], MAX_VARIABLE_NAME, varstring);
						MissionPlot[i][mStep][eStepType][mStepNum] = STEP_CREATEVEHICLE;
						MissionPlot[i][mStep][eArrayNum][mStepNum] = mVehArray;
						mVehArray++;
						mStepNum++;
					}
				}
				else
				{
					#if defined DEBUG
					printf("%s(%i) DEBUG: '%s' set to '%s'", buf, readLine, varstring, string2);
					#endif
					if(isNumeric(string2))
					{
						SetVarValueInt(i, varstring, strval(string2));
					}
					else
					{
						SetVarValueString(i, varstring, string2);
					}
				}
			}
			else if(!sscanf(read, "p<|>'SetVehicleTarget's[" #MAX_VARIABLE_NAME "]i", varstring, int))
			{
				#if defined DEBUG
				printf("%s(%i) DEBUG: SetVehicleTarget(%s, %i)", buf, readLine, varstring, int);
				#endif
				MissionPlot[i][mStep][eStepType][mStepNum] = STEP_SETTARGET;
				MissionPlot[i][mStep][eArrayNum][mStepNum] = mTargetArray;
				format(Mission_TargetCar[mTargetArray][eTC_Var], MAX_VARIABLE_NAME, varstring);
				Mission_TargetCar[mTargetArray][eTC_Toggle] = int;
				mStepNum++;
				mTargetArray++;
			}
			else if(!sscanf(read, "p<|>'GiveMissionMoney'i", int))
			{
				#if defined DEBUG
				printf("%s(%i) DEBUG: GiveMissionMoney(%i)", buf, readLine, int);
				#endif
				MissionPlot[i][mStep][eStepType][mStepNum] = STEP_GIVEMONEY;
				MissionPlot[i][mStep][eArrayNum][mStepNum] = mMoneyArray;
				Mission_Money[mMoneyArray] = int;
				mMoneyArray++;
				mStepNum++;
			}
			else if(!sscanf(read, "'Step 'p<|>iS(auto)[128]", int, string))
			{
				mStep = int-1;
				mStepNum = 0;
				if(strfind(string, "location|", true) != -1)
				{
					if(sscanf(string, "p<|>{s[128]}ffff", X, Y, Z, R)) 
					{
						printf("%s(%i) ERROR: Location must be 'X|Y|Z|R'", buf, readLine);
						break;
					}
					#if defined DEBUG
					printf("%s(%i) DEBUG: Step %i|location|%f|%f|%f|%f", buf, readLine, int, X, Y, Z, R);
					#endif
					MissionMove[i][mStep] = MISSION_LOCATION;
					MissionMove_Location[i][mStep][eMMoveX] = X;
					MissionMove_Location[i][mStep][eMMoveY] = Y;
					MissionMove_Location[i][mStep][eMMoveZ] = Z;
					MissionMove_Location[i][mStep][eMMoveR] = R;
				}
				else if(!strcmp(string, "auto", true))
				{
					#if defined DEBUG
					printf("%s(%i) DEBUG: Step %i|%s", buf, readLine, int, string);
					#endif
					MissionMove[i][mStep] = MISSION_AUTO;
				}
				#if defined DEBUG
				printf("%s(%i) DEBUG: Started parsing step %i", buf, readLine, int);
				#endif
			}
			else if(!strcmp(read, "End", true))
			{
				#if defined DEBUG
				printf("%s(%i) DEBUG: End of mission", buf, readLine);
				#endif
				MissionPlot[i][mStep][eStepType][mStepNum] = STEP_END;
				End = 1;
				if(mStep == -1)
				{
					printf("%s(%i) ERROR: No steps found!", buf, readLine);
					break;
				}
			}
			else printf("%s(%i) ERROR: Invalid expression: %s", buf, readLine, read);
		}
		if(!End) printf("%s(%i) ERROR: No mission end found!", buf, readLine);
		else printf("%s(%i) Successfully parsed \"%s\"\n", buf, readLine, MissionName[i]);
	}
	#if DISPLAY_PARSING_TIME == true
	printf("Completed parsing of all missions in %i milliseconds", tickcount()-tick);
	#endif
	return 1;
}

stock GetVarValueInt(missionid, var[], playerid)
{
	for(new i = 0; i < MAX_VARIABLES; i++)
		if(!strcmp(Variables[missionid][i][eVarName], var, false))
			return Variables_ValuesInt[missionid][playerid][i];
	printf("%s ERROR: Invalid variable: %s", MissionName[missionid], var);
	return 0;
}

stock SetVarValueInt(missionid, var[], value, playerid = -1)
{
	if(playerid == -1)
	{
		for(new j = 0; j < MAX_PLAYERS; j++)
		{
			for(new i = 0; i < MAX_VARIABLES; i++)
			{
				if(!Variables[missionid][i][eVarType] || !strcmp(Variables[missionid][i][eVarName], var, false))
				{
					format(Variables[missionid][i][eVarName], 128, var);
					Variables_ValuesInt[missionid][j][i] = value;
					return 1;
				}
			}
		}
	}
	else
	{
		for(new i = 0; i < MAX_VARIABLES; i++)
		{
			if(!Variables[missionid][i][eVarType] || !strcmp(Variables[missionid][i][eVarName], var, false))
			{
				format(Variables[missionid][i][eVarName], 128, var);
				Variables_ValuesInt[missionid][playerid][i] = value;
				return 1;
			}
		}
	}
	return 0;
}

public Rem_TriggerMission(playerid, missionname[])
	return TriggerMission(playerid, GetMissionID(missionname));

public Rem_TriggerNextStep(playerid, missionname[])
	return TriggerStep(playerid, GetMissionID(missionname))

stock GetMissionID(missionname[])
{
	for(new i = 0; i < MAX_MISSIONS; i++)
	{
		if(strcmp(MissionName[i], missionname, true)) return i;
	}
	return -1;
}
stock GetVarFree()
{
	for(new i = 0; i < MAX_MISSIONS*MAX_PLAYERS*MAX_VARIABLES; i++)
	{
		if(!Variables_String[i][0]) return i;
	}
	return -1;
}

stock SetVarValueString(missionid, var[], value[], playerid = -1)
{
	if(playerid == -1)
	{
		for(new j = 0; j < MAX_PLAYERS; j++)
		{
			for(new i = 0; i < MAX_VARIABLES; i++)
			{
				if(!Variables[missionid][i][eVarType])
				{
					format(Variables[missionid][i][eVarName], 128, var);
					Variables_ValuesString[missionid][j][i] = GetVarFree();
					format(Variables_String[Variables_ValuesString[missionid][j][i]], 128, value);
					return 1;
				}
				else if(!strcmp(Variables[missionid][i][eVarName], var, false))
				{
					format(Variables_String[Variables_ValuesString[missionid][j][i]], 128, value);
					return 1;
				}
			}
		}
	}
	else
	{
		for(new i = 0; i < MAX_VARIABLES; i++)
		{
			if(!Variables[missionid][i][eVarType])
			{
				format(Variables[missionid][i][eVarName], 128, var);
				Variables_ValuesString[missionid][playerid][playerid] = GetVarFree();
				format(Variables_String[Variables_ValuesString[missionid][playerid][playerid]], 128, value);
				return 1;
			}
			else if(!strcmp(Variables[missionid][i][eVarName], var, false))
			{
				format(Variables_String[Variables_ValuesString[missionid][playerid][i]], 128, value);
			}
		}
	}
	return 0;
}

stock IsValidVar(misssionid, var[])
{
	for(new i = 0; i < MAX_VARIABLES; i++)
	{
		if(!strcmp(Variables[missionid][i], var, false)) return 1;
	}
	return 0;
}

stock TriggerMission(playerid, missionid)
{
	if(missionid == -1) return -1;
	CallRemoteFunction("OnMissionTrigger", "is", playerid, MissionName[missionid]);
	Player_Step[playerid][missionid] = 0;
	TriggerStep(playerid, missionid);
	return 1;
}

stock CheckNextStep(playerid, missionid)
{
	new Move = MissionMove[missionid][Player_Step[playerid][missionid]];
	if(Move == MISSION_AUTO
	|| (Move == MISSION_LOCATION 
	&& IsPlayerInRangeOfPoint(playerid, MissionMove_Location[missionid][Player_Step[playerid][missionid]][eMMoveR], MissionMove_Location[missionid][Player_Step[playerid][missionid]][eMMoveX], MissionMove_Location[missionid][Player_Step[playerid][missionid]][eMMoveY], MissionMove_Location[missionid][Player_Step[playerid][missionid]][eMMoveZ]) 
	&& IsPlayerSpawned(playerid)))
	{
		TriggerStep(playerid, missionid);
		return 1;
	}
	return 0;
}

stock TriggerStep(playerid, missionid)
{
	if(missionid == -1) return -1;
	new PlotType;
	new PlotNum;
	new Step = Player_Step[playerid][missionid];
	for(new i = 0; i < MAX_MISSION_SUBSTEPS; i++)
	{
		PlotType = MissionPlot[missionid][Step][eStepType][i];
		PlotNum = MissionPlot[missionid][Step][eArrayNum][i];
		if(PlotType == STEP_MISSIONTEXT)
		{
			SendClientMessage(playerid, COLOR_MISSIONTEXT, ReturnMissionText(PlotNum));
		}
		else if(PlotType == STEP_END)
		{
			CallRemoteFunction("OnMissionEnd", "is", playerid, MissionName[missionid]);
			Player_Step[playerid][missionid] = 0;
			return 1;
		}
		else if(PlotType == STEP_CREATEVEHICLE)
		{
			SetVarValueInt(missionid, Mission_VehicleStorage[PlotNum][eVS_Var], CreateVehicle(Mission_VehicleStorage[PlotNum][eVS_modelid], Mission_VehicleStorage[PlotNum][eVS_X], Mission_VehicleStorage[PlotNum][eVS_Y], Mission_VehicleStorage[PlotNum][eVS_Z], Mission_VehicleStorage[PlotNum][eVS_R], Mission_VehicleStorage[PlotNum][eVS_c1], Mission_VehicleStorage[PlotNum][eVS_c2], Mission_VehicleStorage[PlotNum][eVS_respawn]), playerid);
		}
		else if(PlotType == STEP_SETTARGET)
		{
			SetVehicleParamsForPlayer(GetVarValueInt(missionid, Mission_TargetCar[PlotNum][eTC_Var], playerid), playerid, Mission_TargetCar[PlotNum][eTC_Toggle], 0);
			Veh_Target[playerid][GetVarValueInt(missionid, Mission_TargetCar[PlotNum][eTC_Var], playerid)] = 1;
		}
		else if(PlotType == STEP_GIVEMONEY)
		{
			GivePlayerMoney(playerid, Mission_Money[PlotNum]);
		}
	}
	Player_Step[playerid][missionid]++;
	CheckNextStep(playerid, missionid);
	return 1;
}

stock ReturnMissionText(textid)
{
	new ret[128];
	format(ret, 128, ReplaceFunctions(DisplayText[textid]));
	return ret;
}
stock ReplaceFunctions(text[])
{
	new Display[128];
	new	int, int2, search[128], repl[128];
	format(Display, 128, text);
	sscanf(Display, "{s[128]}p<|>'$rand'ii", int, int2);
	format(search, 128, "$rand|%i|%i", int, int2);
	valstr(repl, randomEx(int, int2));
	Replace(Display, search, repl);
	return Display;
}

//by Y_Less
stock randomEx(minnum = cellmin, maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;

//by DracoBlue
stock isNumeric(const string[]) {
	new length=strlen(string);
	if (length==0) return false;
	for (new i = 0; i < length; i++) {
		if (
		(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+')
		|| (string[i]=='-' && i!=0)
		|| (string[i]=='+' && i!=0)
		) return false;
	}
	if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
	return true;
}

stock Replace(str[], find[], replace[])
{
	new start;
	for(new i = 0; i < strlen(str); i++)
	{
		start = strfind(str, find);
		if(start != -1) 
		{
			if(i == start)
			{
				strdel(str, start, start+strlen(find));
				strins(str, replace, start, 128);
			}
		}
	}
	return 1;
}
stock StripNewLine(string[])
{
	new p = strfind(string, "\r\n");
	if(p != -1)
		strdel(string, p, p+2);
	return 1;
}
public OnFilterScriptInit()
{
	print("\n");
	print("Mission creator v" #MISSIONS_VERSION);
	print("Created by bogeyman_EST");
	print("Starting parsing of missions\n");
	LoadMissions();
	print("Parsing of all missions completed!");
	SetTimer("locationTimer", 1000, true);
	return 1;
}
public OnPlayerConnect(playerid)
{
	IsPSpawned[playerid] = 0;
	return 1;
}
public OnPlayerSpawn(playerid)
{
	IsPSpawned[playerid] = 1;
	return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
	IsPSpawned[playerid] = 0;
	return 1;
}
forward locationTimer();
public locationTimer()
{
	new m = GetMaxPlayers();
	for(new i = 0; i < m; i++)
	{
		if(!IsPlayerConnected(i) || !IsPlayerSpawned(i)) continue;
		for(new j = 0; j < MAX_MISSIONS; j++)
		{
			if(IsPlayerInRangeOfPoint(i, MissionTrigger_Location[j][eMissionR], MissionTrigger_Location[j][eMissionX], MissionTrigger_Location[j][eMissionY], MissionTrigger_Location[j][eMissionZ]))
			{
				if(MissionTrigger[j] == MISSION_LOCATION && Player_Step[i][j] == 0 && WasInArea[i][j])
				{
					TriggerMission(i, j);
					break;
				}
				WasInArea[i][j] = 1;
			}
			else WasInArea[i][j] = 0;
		}
	}
	return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
	for(new i = 0; i < MAX_MISSIONS; i++)
	{
		if(MissionTrigger[i] == MISSION_COMMAND && !strcmp(cmdtext, MissionTrigger_Command[i], true) && Player_Step[playerid][i] == 0)
		{ 
			TriggerMission(playerid, i);
			return 1;
		}
	}
	return 0;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	if(Veh_Target[forplayerid][vehicleid] == 1) SetVehicleParamsForPlayer(vehicleid, forplayerid, 1, 0);
	return 1;
}